GETOPTX
Section: C Library Functions (3)
Updated: local
Index
Return to Main Contents
NAME
getoptx - decode command line options
SYNOPSIS
char getoptx(argc, argv, optstring)
int argc;
char *argv[];
char *optstring;
extern int optind, opterr;
extern char *optarg;
DESCRIPTION
getoptx
returns a character which is either (a) one of the known option characters
specified in
optstring,
(b) a question mark character (?) if the option is unknown or
incorrectly specified, or
EOF
if all options have been returned. If the caller has specified that an
option requires or accepts an argument, the string value of the argument
is returned in
optarg.
In the case of an optional argument
optarg
may point to an empty ("") string.
Format of optstring
optstring
contains the values of the option characters which are recognized. In
addition any character may be followed by a colon (:) is it requires an
argument, or an asterisk (*) if it accepts an optional argument.
Format of the command line
The command line parsed by
getoptx
consists of the command name, followed by zero or more options separated
by blanks, followed by arguments to the command. The options are ended
by any of (a) the end of data on the command line, (b) a token which
does not start with a hyphen (-), or (c) the special token --.
Using ? as a valid option
Although
getoptx
returns the ? as an indication of an unknown option, or one used
without a required argument, the ? may be included in the
optstr
so that ? becomes a known option. The effect is that specifying any
invalid option will generate an error message, while using -? as an
option does not. In either case a ? returned from
getoptx
can be used to display a usage message.
EXAMPLES
cval = getoptx(argc, argv, "al:sD*");
The options 'a' and 's' are returned without arguments. The option 'l'
requires an argument, which may be part of the same command line token
as the option (as:~-l40) or as the following token (as:~-c~40). The
option 'D' may be immediately followed by an argument, and if there is
no argument it must be the last option in the token.
WARNINGS
A warning message is displayed on
stderr
and the character ? is returned is either (a) an option character not in
optstr
is found, or (b) a known option which requires an argument does not have
one. If the variable
opterr
is set to zero the warning message will not be displayed.
SEE ALSO
LIMITATIONS
The characters colon (:) and asterisk (*) may not be option characters.
AUTHOR
Man page by Bill Davidsen (davidsen@crdos1.crd.ge.com). Original getopt
source attributed to AT&T public domain version from 1985 UNIFORUM,
changes by Bill Davidsen. All original work by Bill Davidsen is hereby
placed in the public domain.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- Format of optstring
-
- Format of the command line
-
- Using ? as a valid option
-
- EXAMPLES
-
- WARNINGS
-
- SEE ALSO
-
- LIMITATIONS
-
- AUTHOR
-
This document was created by
man2html,
using the manual pages.
Time: 02:52:25 GMT, February 09, 2023